﻿<style>
    #div-projectlog .layui-table-cell{
        padding: 0px!important;
    }
</style>
<div class="layui-row">
    <div class="layui-col-md9">
        <div class="layui-body-nav">资料 / 笔记资料
            <button type="button" class="layui-btn layui-btn-xs" id="test3"><i class="layui-icon">
                &#xe67c;</i>上传
            </button>
        </div>
        <table class="layui-hide" id="table-projectattach" lay-filter="table-projectattach"></table>
    </div>
    <div class="layui-col-md3" id="div-projectlog">
        <table class="layui-hide" id="table-projectlog" lay-filter="table-projectlog"></table>
    </div>
</div>
<!-- layui规范化用法 -->
<script type="text/javascript">
    var table;
    workUtils.onclick(".attach-down", function (c) {
        var id = $(c).attr("data-id");
        location.href = "../project/downattach/"+id;
    });

    /*加载资料表格*/
    function loadDefaultData() {
        table.reload("table-projectattach", {
            where: {
                projectId: workUtils.get("projectId")
            }
        });
        table.reload("table-projectlog", {
            where: {
                projectId: workUtils.get("projectId")
            }
        });
    }
    /*构建html*/
    function buildLogsHtml(item) {
        var html = '';
        html += '<div class="layui-row">';
        html += '<div class="layui-col-md2" style="text-align: center;">';
        html += '<img src="../photo/get/' + item.user.id + '"  class="layui-nav-img user-photo" style="width: 32px;height: 32px;margin: 0 auto;">';
        html += '<div style="font-size: 12px;">' + item.user.name + '</div>';
        html += '</div>';
        html += '<div class="layui-col-md10" style="background-color: #fafafa;min-height: 47px;">';
        html += '<div style="font-size: 8px;color: #bbb;">';
        html += workUtils.toDate(item.created, 'yyyy-MM-dd hh');
        html += '</div>';
        html += '<div style="word-break: break-all;white-space: normal;">';
        html += item.detail;
        html += '</div>';
        html += "</div></div>";
        return html;
    }

    layui.use(['layer', 'table', 'upload'], function () {
        table = layui.table;
        var upload = layui.upload;
        upload.render({ //允许上传的文件后缀
            elem: '#test3'
            , url: '../project/upload/file'
            , accept: 'file' //普通文件
            , data: {projectId: workUtils.get("projectId")}
            , size: 20000
            , done: function (res) {
                loadDefaultData();
            }
        });

        table.render({
            elem: '#table-projectattach'
            , url: '../project/listattach'
            , height: 'full-145'
            , cols: [[
                {field: 'name', title: '标题', width: 'auto', align: 'left', event: 'edit'}
            ]]
            ,done: function (res, curr, count) {
            }
            , where: {
                projectId: workUtils.get("projectId")
            }
            , page: true
            , cell: function (field, item) {
                var html = '<div class="title">' + item.fileName + '</div>';
                html += '<div class="layui-row">';
                html += '<div class="layui-col-md8">';
                html += workUtils.toDate(item.created,'yyyy-MM-dd hh') +' By '+item.userName;
                html += '</div>';
                html += '<div class="layui-col-md4  menu-bars">';
                html += '<a class="layui-btn layui-btn-danger layui-btn-xs attach-down" data-id="' + item.id + '">下载</a>';
                html += '</div>';
                html += '</div>';
                return html;
            }
        });
        table.render({
            elem: '#table-projectlog'
            , url: '../project/listlog'
            , height: 'full-115'
            , cols: [[
                {field: 'name', title: '标题', width: 'auto', align: 'left', event: 'edit'}
            ]]
            ,done: function (res, curr, count) {
            }
            , where: {
                projectId: workUtils.get("projectId")
            }
            , page: {
                layout: ['prev', 'next'],
                prev: '上一页',
                next: '下一页',
            }
            , cell: function (field, item) {
                return buildLogsHtml(item);
            }
        });
    });

</script>